<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>django.forms.extras.widgets &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../../../index.html" />
    <link rel="up" title="django.forms" href="../../forms.html" />



 
<script type="text/javascript" src="../../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    <a href="../../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="_modules-django-forms-extras-widgets">
            
  <h1>Source code for django.forms.extras.widgets</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Extra HTML Widget classes</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">unicode_literals</span>

<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">import</span> <span class="nn">re</span>

<span class="kn">from</span> <span class="nn">django.forms.widgets</span> <span class="kn">import</span> <span class="n">Widget</span><span class="p">,</span> <span class="n">Select</span>
<span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">datetime_safe</span>
<span class="kn">from</span> <span class="nn">django.utils.dates</span> <span class="kn">import</span> <span class="n">MONTHS</span>
<span class="kn">from</span> <span class="nn">django.utils.encoding</span> <span class="kn">import</span> <span class="n">force_str</span>
<span class="kn">from</span> <span class="nn">django.utils.safestring</span> <span class="kn">import</span> <span class="n">mark_safe</span>
<span class="kn">from</span> <span class="nn">django.utils.formats</span> <span class="kn">import</span> <span class="n">get_format</span>
<span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">six</span>
<span class="kn">from</span> <span class="nn">django.conf</span> <span class="kn">import</span> <span class="n">settings</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;SelectDateWidget&#39;</span><span class="p">,)</span>

<span class="n">RE_DATE</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">r&#39;(\d{4})-(\d\d?)-(\d\d?)$&#39;</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">_parse_date_fmt</span><span class="p">():</span>
    <span class="n">fmt</span> <span class="o">=</span> <span class="n">get_format</span><span class="p">(</span><span class="s">&#39;DATE_FORMAT&#39;</span><span class="p">)</span>
    <span class="n">escaped</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="n">output</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">char</span> <span class="ow">in</span> <span class="n">fmt</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">escaped</span><span class="p">:</span>
            <span class="n">escaped</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">elif</span> <span class="n">char</span> <span class="o">==</span> <span class="s">&#39;</span><span class="se">\\</span><span class="s">&#39;</span><span class="p">:</span>
            <span class="n">escaped</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">elif</span> <span class="n">char</span> <span class="ow">in</span> <span class="s">&#39;Yy&#39;</span><span class="p">:</span>
            <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;year&#39;</span><span class="p">)</span>
            <span class="c">#if not self.first_select: self.first_select = &#39;year&#39;</span>
        <span class="k">elif</span> <span class="n">char</span> <span class="ow">in</span> <span class="s">&#39;bEFMmNn&#39;</span><span class="p">:</span>
            <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;month&#39;</span><span class="p">)</span>
            <span class="c">#if not self.first_select: self.first_select = &#39;month&#39;</span>
        <span class="k">elif</span> <span class="n">char</span> <span class="ow">in</span> <span class="s">&#39;dj&#39;</span><span class="p">:</span>
            <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;day&#39;</span><span class="p">)</span>
            <span class="c">#if not self.first_select: self.first_select = &#39;day&#39;</span>
    <span class="k">return</span> <span class="n">output</span>


<div class="viewcode-block" id="SelectDateWidget"><a class="viewcode-back" href="../../../../ref/forms/widgets.html#django.forms.extras.widgets.SelectDateWidget">[docs]</a><span class="k">class</span> <span class="nc">SelectDateWidget</span><span class="p">(</span><span class="n">Widget</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A Widget that splits date input into three &lt;select&gt; boxes.</span>

<span class="sd">    This also serves as an example of a Widget that has more than one HTML</span>
<span class="sd">    element and hence implements value_from_datadict.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">none_value</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s">&#39;---&#39;</span><span class="p">)</span>
    <span class="n">month_field</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_month&#39;</span>
    <span class="n">day_field</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_day&#39;</span>
    <span class="n">year_field</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_year&#39;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attrs</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">years</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">months</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">attrs</span> <span class="o">=</span> <span class="n">attrs</span> <span class="ow">or</span> <span class="p">{}</span>

        <span class="c"># Optional list or tuple of years to use in the &quot;year&quot; select box.</span>
        <span class="k">if</span> <span class="n">years</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">years</span> <span class="o">=</span> <span class="n">years</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">this_year</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">()</span><span class="o">.</span><span class="n">year</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">years</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">this_year</span><span class="p">,</span> <span class="n">this_year</span> <span class="o">+</span> <span class="mi">10</span><span class="p">)</span>

        <span class="c"># Optional dict of months to use in the &quot;month&quot; select box.</span>
        <span class="k">if</span> <span class="n">months</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">months</span> <span class="o">=</span> <span class="n">months</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">months</span> <span class="o">=</span> <span class="n">MONTHS</span>

    <span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">attrs</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">year_val</span><span class="p">,</span> <span class="n">month_val</span><span class="p">,</span> <span class="n">day_val</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">year</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">day</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="n">year_val</span> <span class="o">=</span> <span class="n">month_val</span> <span class="o">=</span> <span class="n">day_val</span> <span class="o">=</span> <span class="bp">None</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">six</span><span class="o">.</span><span class="n">string_types</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">USE_L10N</span><span class="p">:</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">input_format</span> <span class="o">=</span> <span class="n">get_format</span><span class="p">(</span><span class="s">&#39;DATE_INPUT_FORMATS&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                        <span class="n">v</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">force_str</span><span class="p">(</span><span class="n">value</span><span class="p">),</span> <span class="n">input_format</span><span class="p">)</span>
                        <span class="n">year_val</span><span class="p">,</span> <span class="n">month_val</span><span class="p">,</span> <span class="n">day_val</span> <span class="o">=</span> <span class="n">v</span><span class="o">.</span><span class="n">year</span><span class="p">,</span> <span class="n">v</span><span class="o">.</span><span class="n">month</span><span class="p">,</span> <span class="n">v</span><span class="o">.</span><span class="n">day</span>
                    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                        <span class="k">pass</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">match</span> <span class="o">=</span> <span class="n">RE_DATE</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">match</span><span class="p">:</span>
                        <span class="n">year_val</span><span class="p">,</span> <span class="n">month_val</span><span class="p">,</span> <span class="n">day_val</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">match</span><span class="o">.</span><span class="n">groups</span><span class="p">()]</span>
        <span class="n">choices</span> <span class="o">=</span> <span class="p">[(</span><span class="n">i</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">years</span><span class="p">]</span>
        <span class="n">year_html</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_select</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">year_field</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">year_val</span><span class="p">,</span> <span class="n">choices</span><span class="p">)</span>
        <span class="n">choices</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">six</span><span class="o">.</span><span class="n">iteritems</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">months</span><span class="p">))</span>
        <span class="n">month_html</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_select</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">month_field</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">month_val</span><span class="p">,</span> <span class="n">choices</span><span class="p">)</span>
        <span class="n">choices</span> <span class="o">=</span> <span class="p">[(</span><span class="n">i</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">32</span><span class="p">)]</span>
        <span class="n">day_html</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">create_select</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">day_field</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">day_val</span><span class="p">,</span> <span class="n">choices</span><span class="p">)</span>

        <span class="n">output</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">field</span> <span class="ow">in</span> <span class="n">_parse_date_fmt</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">field</span> <span class="o">==</span> <span class="s">&#39;year&#39;</span><span class="p">:</span>
                <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">year_html</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">field</span> <span class="o">==</span> <span class="s">&#39;month&#39;</span><span class="p">:</span>
                <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">month_html</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">field</span> <span class="o">==</span> <span class="s">&#39;day&#39;</span><span class="p">:</span>
                <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">day_html</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">mark_safe</span><span class="p">(</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">id_for_label</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">id_</span><span class="p">):</span>
        <span class="n">first_select</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="n">field_list</span> <span class="o">=</span> <span class="n">_parse_date_fmt</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">field_list</span><span class="p">:</span>
            <span class="n">first_select</span> <span class="o">=</span> <span class="n">field_list</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">first_select</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">id_</span><span class="p">,</span> <span class="n">first_select</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_month&#39;</span> <span class="o">%</span> <span class="n">id_</span>

    <span class="k">def</span> <span class="nf">value_from_datadict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">files</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">year_field</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="n">m</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">month_field</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">day_field</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">y</span> <span class="o">==</span> <span class="n">m</span> <span class="o">==</span> <span class="n">d</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="n">y</span> <span class="ow">and</span> <span class="n">m</span> <span class="ow">and</span> <span class="n">d</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">USE_L10N</span><span class="p">:</span>
                <span class="n">input_format</span> <span class="o">=</span> <span class="n">get_format</span><span class="p">(</span><span class="s">&#39;DATE_INPUT_FORMATS&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">date_value</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="n">m</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">))</span>
                <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                    <span class="k">return</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">-</span><span class="si">%s</span><span class="s">-</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">date_value</span> <span class="o">=</span> <span class="n">datetime_safe</span><span class="o">.</span><span class="n">new_date</span><span class="p">(</span><span class="n">date_value</span><span class="p">)</span>
                    <span class="k">return</span> <span class="n">date_value</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">input_format</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">-</span><span class="si">%s</span><span class="s">-</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">create_select</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">field</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">choices</span><span class="p">):</span>
        <span class="k">if</span> <span class="s">&#39;id&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">attrs</span><span class="p">:</span>
            <span class="n">id_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">attrs</span><span class="p">[</span><span class="s">&#39;id&#39;</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">id_</span> <span class="o">=</span> <span class="s">&#39;id_</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">name</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_required</span><span class="p">:</span>
            <span class="n">choices</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">none_value</span><span class="p">)</span>
        <span class="n">local_attrs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_attrs</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="n">field</span> <span class="o">%</span> <span class="n">id_</span><span class="p">)</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">Select</span><span class="p">(</span><span class="n">choices</span><span class="o">=</span><span class="n">choices</span><span class="p">)</span>
        <span class="n">select_html</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">field</span> <span class="o">%</span> <span class="n">name</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">local_attrs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">select_html</span></div>
</pre></div>

          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3>Browse</h3>
  <ul>
    
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../../../index.html">Module code</a>
        
          <ul><li><a href="../../../django.html">django</a>
        
          <ul><li><a href="../../forms.html">django.forms</a>
        
        <ul><li>django.forms.extras.widgets</li></ul>
        </li></ul></li></ul></li></ul>
      </li>
  </ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    <a href="../../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>